package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.SparePartReplaceRecordDao;
import com.sugon.entity.SparePartReplaceRecord;
import com.sugon.service.SparePartReplaceRecordService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 关键备件Service实现类
 *
 * @author YuXD
 * @date 2023-06-23
 */
@Service("sparePartReplaceRecordService")
public class SparePartReplacePartServiceImpl implements SparePartReplaceRecordService {

    @Autowired
    private SparePartReplaceRecordDao replaceRecordDao;

    @Override
    public boolean save(SparePartReplaceRecord replaceRecord) {
        replaceRecord.setId(RandomUtil.randomString(36));
        replaceRecord.setCreateBy(ShiroUtils.getUserId());
        replaceRecord.setCreateTime(DateUtil.date());
        return replaceRecordDao.save(replaceRecord) > 0;
    }

    @Override
    public boolean update(SparePartReplaceRecord replaceRecord) {
        replaceRecord.setUpdateBy(ShiroUtils.getUserId());
        replaceRecord.setUpdateTime(DateUtil.date());
        return replaceRecordDao.update(replaceRecord) > 0;
    }

    @Override
    public SparePartReplaceRecord findOngoingReplaceRecord(String sparePartKeyId) {
        return replaceRecordDao.findOngoingReplaceRecord(sparePartKeyId);
    }
}
